package wickethub.web.components.syntax;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.resources.JavascriptResourceReference;

public class SyntaxHighlighterBehavior extends AbstractAjaxBehavior {
	
	private static final ResourceReference SH_MAIN_JAVASCRIPT = 
		new JavascriptResourceReference(SyntaxHighlighterBehavior.class, "sh_main.min.js");
	
	private static final ResourceReference SH_JAVA_JAVASCRIPT = 
		new JavascriptResourceReference(SyntaxHighlighterBehavior.class, "sh_java.min.js");

	private static final ResourceReference SH_CSS = 
		new JavascriptResourceReference(SyntaxHighlighterBehavior.class, "sh_style.min.css");

	
	@Override
	protected void onBind() {
		super.onBind();
		getComponent().setOutputMarkupId(true);
		getComponent().setEscapeModelStrings(false);
		getComponent().add(new SimpleAttributeModifier("class", "sh_java"));
	}
	
	public void onRequest() {
	}
	
	@Override
	public void renderHead(IHeaderResponse response) {
		super.renderHead(response);
		response.renderJavascriptReference(SH_MAIN_JAVASCRIPT);
		response.renderJavascriptReference(SH_JAVA_JAVASCRIPT);
		response.renderCSSReference(SH_CSS);
		response.renderOnDomReadyJavascript("sh_highlightDocument();");
	}

}
